package com.ruge.system.controller;

import com.ruge.common.util.RestResponse;
import com.ruge.system.pojo.entity.Notice;
import com.ruge.system.pojo.request.NoticeRequest;
import com.ruge.system.service.SysNoticeService;
import com.ruge.system.pojo.vo.NoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ：爱丽丝、如歌
 * @time ：2020/3/12  21:55
 * 描述 ： 公告管理
 */
@Slf4j
@RestController
@RequestMapping("/notice")
@Api(value = "公告管理controller", tags = {"公告管理操作接口"})
public class SysNoticeController {
    @Resource
    private SysNoticeService noticeService;

    @PostMapping("/list")
    @ApiOperation(value = "获取公告详细信息", notes = "根据url的id来获取公告详细信息")
    public RestResponse list(@RequestBody(required = false) NoticeRequest request) {
        Page<NoticeVo> page = noticeService.findAll(request);
        return RestResponse.success().setData(page);
    }

    @PostMapping
    @ApiOperation(value = "保存公告详细信息")
    public RestResponse save(@RequestBody Notice model) {
        return RestResponse.success().setData(noticeService.save(model));
    }

    @ApiOperation(value = "更新公告详细信息")
    @PutMapping
    public RestResponse update(@RequestBody Notice model) {
        return RestResponse.success().setData(noticeService.save(model));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除公告", notes = "根据url的id来指定删除对象")
    public RestResponse delete(@PathVariable Long id) {
        noticeService.deleteById(id);
        return RestResponse.success();
    }

    @ApiOperation(value = "批量操作", notes = "根据url的id来指定批量操作对象")
    @PostMapping("/batch")
    public RestResponse batch(@RequestBody Map<String, List<Notice>> map) {
        return RestResponse.success().setData(noticeService.batch(map));
    }
}
